// Loesung_von_Aufgabe_2.2.5_1_Eimer

// Schräger Wurf mit unterschiedlichen Winkel

float x = 0; // x-Wert für den Mittelpunkt des Balls
float y0 = 200; // Abwurfhöhe
float y = 0; // y-Wert für den Mittelpunkt des Balls
float v0 = 57; // Abwurfgeschwindigkeit
float g = 9.81; // Erdbeschleunigung
float t = 0; // Zeit
float winkel = 45; // Winkel in Grad

void setup() 
{
  size(700, 300);
  frameRate(30);
}

void draw() 
{
  background (240);
  fill(0, 0, 255); // Schriftfarbe
  textSize(24); // Schriftgröße
  text("schräger Wurf", 250, 50); 

  x = v0*t*cos(radians(winkel)); //  Bewegung in x-Richtung
  y = y0 - v0*t*sin(radians(winkel)) + 0.5*g*t*t; // Bewegung in y-Richtung
  t = t + 0.1;

  fill(255, 0, 0);
  ellipse(x, y, 10, 10); // roter Ball

  fill(150);
  rect(0, y0 + 5, 20, 300); // graue Abschussrampe

  fill(0, 0, 255, 10);
  rect(x-15, 270, 50, 30); // blauer, transparenter Eimer

  // Angabe ob der Eimer getroffen wurde
  if (y > 290 && y < 305) 
  {
    fill(255, 0, 0);
    textSize(40);
    text("Treffer bei x = " +round(x), 150, 130 );
    noLoop();
  }
}